// utils/watch.js
function observe(obj, key, callback, page) {
    let val = obj[key];
    Object.defineProperty(obj, key, {
      configurable: true,
      enumerable: true,
      set(newVal) {
        if (newVal !== val) {

          val = newVal;     
          page.setData({ [key]: newVal }); // 👈 加上这一句     
          callback.call(page, newVal, val);
          
        }
      },
      get() {
        return val;
      }
    });
  }
  
  export function setWatcher(page) {
    const watch = page.watch;
    Object.keys(watch).forEach(key => {
      observe(page.data, key, watch[key], page);
    });
  }
  
 
module.exports = {
    setWatcher
}
